/**
 * @program: LeetCode
 * @description: LeetCode : 相同的树
 * @author: WXY
 * @create: 2023-02-14 19:28
 * @Version 1.0
 **/
public class Num100_isSameTree_1 {
    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;
        TreeNode() {}
        TreeNode(int val) { this.val = val; }
        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }

    public boolean isSameTree(TreeNode head1, TreeNode head2) {
        if (head1 == null && head2 == null) return true;
        if (head1 != null && head2 == null) return false;
        if (head1 == null && head2 != null) return false;
        if (head1.val != head2.val) return false;
        return isSameTree(head1.left, head2.left) && isSameTree(head1.right, head2.right);
    }
}
